<?php
/**
 * *********************************************************************************************************************
 * 申通快递派件通知收件人支付宝服务窗接口
 * *********************************************************************************************************************
 */
namespace soa\message;
use soa\message\alipayServiceWindow\serviceWindow;

class stoExpressAlipay extends serviceWindow
{
    /**
     * 接口地址
     * @var string
     */
    private $alipayMethod = 'alipay.mobile.public.message.matcher.send';
    /**
     * appId
     * @var string
     */
    private $appId = '2015051800078634';

    /**
     * @var string
     */
    private $templateId = 'd9d333d066314b688e497b9117d2776f';

    /**
     * 打包数据请求到alipay服务窗
     * @param $mobile
     * @param $first
     * @param $waybillNo
     * @param $status
     * @param $remark
     * @return bool|string
     */
    public function sendToAlipay($mobile, $first, $waybillNo, $status, $remark)
    {
        if(empty($mobile) || !preg_match('/^\d{11}$/i', $mobile)) {
            return false;
        }
        $bizContent = [
            'matcher' => [
                'mobileNo' => $mobile
            ],
            'template' => [
                'templateId' => $this->getTemplateId(),
                'context' => [
                    "headColor" => "#ed6900",
                    'first'  => [
                        'color' => '#ed6900',
                        'value' => $first
                    ],

                    'keyword1' => [
                        'color' => '#000000',
                        'value' => $waybillNo
                    ],

                    'keyword2' => [
                        'color' => '#000000',
                        'value' => $status
                    ],

                    'remark' => [
                        'color' => '#000000',
                        'value' => $remark
                    ]
                ]
            ]
        ];

        $result = $this->send($this->getAppId(), $this->getAlipayMethod(), array('biz_content' => $bizContent));
        if($result['code']==200) {
            return true;
        } else {
            $breakPoint = str_replace('.', '_', $this->getAlipayMethod()) . '_response';
            logDebug('code:'.$result['code'].', msg:'. $result['msg'], $breakPoint);
            return $result['msg'];
        }
    }

    public function getAlipayMethod()
    {
        return $this->alipayMethod;
    }

    public function getAppId()
    {
        return $this->appId;
    }

    public function getTemplateId()
    {
        return $this->templateId;
    }
}